package com.bocai.dahuatech.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bocai.dahuatech.R;

import java.util.ArrayList;
import java.util.List;

public class FlowAdapter<T> extends BaseAdapter{
private final Context mContext;
    private final List<T> mDataList;

    public FlowAdapter(Context context) {
        this.mContext = context;
        mDataList = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }

    @Override
    public Object getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    class ViewHolder{
                TextView tv;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView  = LayoutInflater.from(mContext).inflate(R.layout.product_type_item, null);
            viewHolder.tv = (TextView) convertView.findViewById(R.id.tv_tag);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv.setText(mDataList.get(position).toString());
        return convertView;
    }

    public void onlyAddAll(List<T> datas) {
        mDataList.addAll(datas);
        notifyDataSetChanged();
    }

//    public void clearAndAddAll(List<T> datas) {
//        mDataList.clear();
//        onlyAddAll(datas);
//    }
}
